<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
    <title>Document</title>
</head>

<body>
    <div id="app">
        <p>输入搜索：<input type="text" v-model="msg">使用watch监听</p>
        <p>输入搜索：<input type="text" v-model="msg">使用computed属性</p>
        <button @click="changaName">xiugaimingzi</button>
        <h3>{{goodData.name}}</h3>
        <h3>{{msg + "hahaha"}}</h3>
        <p>名字<input type="text" v-model="goodData.name"></p>
        <p>年龄<input type="text" v-model="goodData.age"></p>
        <p>性别<input type="text" v-model="goodData.sex"></p>
    </div>
    <script>
        const vm = new Vue({
            data(){
                return{
                  msg:"时间",
                  goodData:{
                    name:"zhangsan",
                    age:"18",
                    sex:"nan"
                  }
                }
            },
            watch:{
                msg(val,oldVal){
                    console.log("更新了msg");
                    console.log(val,oldVal);
                },
                //监听单一属性
                "goodData.name"(){

                    console.log("gengxinglemingzi");
                },
                //监听对象
                goodData:{
                    deep:true,
                    handler(value,oldValue){ //监听的是对象时 新旧数据是同样的
                        console.log(value,oldValue);
                    }
                }
            },
            methods: {
                changaName(){
                    this. goodData.name = "lisi"
                }
            },
           
        }).$mount("#app")
    </script>
</body>

</html>